<section >
    <div class="container">
        <div class="row">
            <div class="span12">	            	
                <ul class="breadcrumb">
                    <li class="previous"><a href="<?php echo SITE_URL; ?>">Home /</a></li>                
                    <li class="disable"><a href="javascript:void(0);">Manage My Courses</a></li>
                </ul>  

                <div class="common">
                    <div class="whiteBg padding10px">
                        <h5 class="fnt-size20 addBution" >Manage My Courses</h5><h5><a href="javascript:void(0)" class="btn-green " onclick="checkProfile('Classes/Create');">Create a Class </a>
                            <a href="javascript:void(0)" class="btn-green " onclick="checkProfile('Courses/Create');">Create a Course</a>
                            <div id="formResult" class="errorMessage"></div></h5> 
                    </div>
                </div>
                <div class="common sortingDiv">                
                    <fieldset>
                        <div class="col">
                            <p class="sorttxt inline-block">Sort By</p>
                        </div>            
                        <div class="col">   
                            <select class="selectsort" id="sort_class_type" name="sort_location">
                                <option value="">Select Course</option>
                                <option value="1">Current Course</option>
                                <option value="2">Upcoming Course</option>
                                <option value="3">Previous Course</option>
                            </select>
                        </div>
                        <div class="col">                            
                            <select class="selectsort" id="sort_location" name="sort_location">
                                <option value="">Select</option>
                                <?php
                                foreach ($classVenueVals as $classVenueVal) {
                                    echo '<option value=' . $classVenueVal->id . '>' . $classVenueVal->venue_locality . '</option> ';
                                }
                                ?>

                            </select>
                        </div>
                        <div class="col">   
                            <select class="selectsort" id="sort_popular" name="sort_location">
                                <option value="">Select Popular Course</option>
                                <option value="">Popular Course</option>

                            </select>
                        </div>

                    </fieldset>
                    <div class="clear"></div>
                </div>
                <div id="AjaxLoader" style="display:none;" align="center">&nbsp;<img src="<?php echo ThemePath(); ?>/images/fancybox_loading@2x.gif" align="absmiddle"></div>
                <?php
                $this->widget('zii.widgets.CListView', array(
                    'dataProvider' => $dataProvider,
                    'afterAjaxUpdate' => 'reinstallCheckBox',
                    'id' => 'ajaxListView',
                    'summaryText' => '',
                    'itemView' => '_view',
                ));
                Yii::app()->clientScript->registerScript('reinstallCheckBox', "
function reinstallCheckBox(id, data) {   
    $('.flatui').fancyfields({
            onCheckboxChange: function(input, isChecked) {
                var array = input.attr('id').split('_');            
                var allVals = [];
                if (isChecked) {
                    $('#send_user_details_class_' + array[4] + '_checkbox_' + array[6]).addClass('current_checked_' + array[4]);
                    $('.current_checked_' + array[4]).each(function() {
                        allVals.push($(this).val());
                    });
                     $('#select_All_' + array[4]).fancyfields('unchecked');
                    $('#get_checked_value_' + array[4]).val(allVals);

                } else {
                    $('#send_user_details_class_' + array[4] + '_checkbox_' + array[6]).removeClass('current_checked_' + array[4]);
                    $('.current_checked_' + array[4]).each(function() {
                        allVals.push($(this).val());
                    });
                     $('#select_All_' + array[4]).fancyfields('unchecked');
                    $('#get_checked_value_' + array[4]).val(allVals);
                    $('.selected_checkbox_' + array[6]).fancyfields('unchecked');
                }

            }});
    $('.selectAllcheckbox').fancyfields({
            onCheckboxChange: function(input, isChecked) {
                var array = input.attr('id').split('_');
                var allVals = [];
                if (isChecked) {  
                 $('.selected_checkbox_' + array[2]).addClass('current_checked_' + array[2]);
                 $('.selected_checkbox_'+ array[2]).each(function() {
                        allVals.push($(this).val());
                    });
                    
                    $('#get_checked_value_'+ array[2]).val(allVals);
                    $('.selected_checkbox_'+ array[2]).fancyfields('checked');
                } else {
                  $('.selected_checkbox_' + array[2]).removeClass('current_checked_' + array[2]);
                    $('#get_checked_value_' + array[2]).val('');
                    $('.selected_checkbox_' + array[2]).fancyfields('unchecked');
                }
            }});
            

}
");
                ?>
            </div>
        </div>
    </div>
    <?php
    Yii::app()->clientScript->registerScript('search', "var ajaxUpdateTimeout;
    var ajaxRequest;
    $('.selectsort').fancyfields({
	onSelectChange: function() {	
	var sort_locationval=$('#sort_location').val();
	var sort_class_type=$('#sort_class_type').val();
	var sort_converted_unconverted=$('#sort_converted_unconverted').val();
        ajaxRequest = '&location=' + sort_locationval+'&classType=' + sort_class_type+'&converted_unconverted=' + sort_converted_unconverted;
        clearTimeout(ajaxUpdateTimeout);
        ajaxUpdateTimeout = setTimeout(function () {
            $.fn.yiiListView.update(
                'ajaxListView',
                {data: ajaxRequest}
            )
        },
        300);}
    });"
    )
    ?>
</section>
<div class="padding20px"></div>
<?php
$allClassCourseInfo = array();
$classDetails = literalEndingTommorow('', '', '');
$courseDetails = runningCurrentCoursesByUser('', '', ''); //Null parameter means these value $profiles, $userType, $getValue)
$allClassCourseInfo = array_merge($classDetails, $courseDetails);
usort($allClassCourseInfo, 'date_compare');
$validatedata = literalendingtommorowValiadte($allClassCourseInfo);
if (!empty($validatedata)) {
    $this->renderPartial('/classes/literallyEndingtomorrow', array('allClassCourseInfo' => $allClassCourseInfo));
}
?>
<script src="<?php echo ThemePath(); ?>/js/responsiveCarousel.js" type="text/javascript"></script>
<script type="text/javascript" src="<?php echo ThemePath(); ?>/js/jquery.nicescroll.js"></script>

<script type="text/javascript">
    jQuery(document).ready(function() {
        jQuery('#reviewCarousel').carousel({
            interval: 4000
        })

    });

    jQuery(document).ready(function($) {
        $('.crsl-items1').respCaro({overflow: false, visible: 3, itemMinWidth: 300, itemMargin: 20, autoRotate: 5000});

    });
    jQuery(document).ready(function() {

        $('.selectAllcheckbox').fancyfields({
            onCheckboxChange: function(input, isChecked) {
                var array = input.attr('id').split('_');
                var allVals = [];
                if (isChecked) {
                    $('.selected_checkbox_' + array[2]).each(function() {
                        allVals.push($(this).val());
                    });
                    $('#get_checked_value_' + array[2]).val(allVals);
                    $('.selected_checkbox_' + array[2]).fancyfields('checked');
                    $('.selected_checkbox_' + array[2]).addClass('current_checked_' + array[2]);
                } else {
                    $('.selected_checkbox_' + array[2]).removeClass('current_checked_' + array[2]);
                    $('#get_checked_value_' + array[2]).val('');
                    $('.selected_checkbox_' + array[2]).fancyfields('unchecked');
                }
            }});
        $(".flatui").fancyfields({
            onCheckboxChange: function(input, isChecked) {
                var array = input.attr('id').split('_');
                var allVals = [];
                if (isChecked) {
                    $('#send_user_details_class_' + array[4] + '_checkbox_' + array[6]).addClass('current_checked_' + array[4]);
                    $('.current_checked_' + array[4]).each(function() {
                        allVals.push($(this).val());
                    });
                    $('#select_All_' + array[4]).fancyfields('unchecked');
                    $('#get_checked_value_' + array[4]).val(allVals);
                } else {
                    $('#send_user_details_class_' + array[4] + '_checkbox_' + array[6]).removeClass('current_checked_' + array[4]);
                    $('.current_checked_' + array[4]).each(function() {
                        allVals.push($(this).val());
                    });
                    $('#select_All_' + array[4]).fancyfields('unchecked');
                    $('#get_checked_value_' + array[4]).val(allVals);
                    $('.selected_checkbox_' + array[6]).fancyfields('unchecked');
                }

            }});
        $(".customSBDemo").fancyfields({customScrollBar: false});
        $("#demoReset").click(function() {
            $(".flatui").fancyfields("reset");
            $(".customSBDemo").fancyfields("reset");
        });
    });
    function sendMessageToConevertedUser(id) {
        if ($("#get_checked_value_" + id).val() != '') {
            $(".sendMessageTouser").hide();
            $("#send_message_" + id).hide();
            $('#review_cancel_btn_' + id).show();
            $('.edit_class_details'+id).hide();
            $('.view_class_details'+id).hide();
            $(".active_status_class_details" + id).hide();
            $("#send_message_to_users_" + id).show();
            $(".errorMessage").text('');
            $("#send_a_msg_box_" + id).show("slow", function() {
                // Animation complete.
            });
        }
        else {
            $("#error_text_not_checked_" + id).text('Please check at least one checkbox.');
        }



    }

    function sendAMailToAllConvertedUser(id) {
        var selectedUser = $("#get_checked_value_" + id).val();
        var subject = $("#subject_" + id).val();
        var msgval = $("#message_text_" + id).val();
        if (subject == '') {
            $("#errorMessage_subject_" + id).text('Subject can not blank.');
            return false;
        }

        if (msgval == '') {
            $("#errorMessage_subject_" + id).text('');
            $("#errorMessage_msg_" + id).text('Message  can not blank.')
            return false;
        }
        if (selectedUser == '') {
            $("#errorMessage_subject_" + id).text('');
            $("#errorMessage_msg_" + id).text('Please select at least one user.')
            return false;
        }

        if (subject != '' && msgval != '' && selectedUser!='') {           
            jQuery.ajax({
                'type': 'POST',
                'url': "<?php echo Yii::app()->createAbsoluteUrl("MailConversation/sendMailTouser"); ?>",
                'data': "selectedUser=" + selectedUser + "&subject=" + subject + "&msgval=" + msgval + "&classId=" + id+"&type=course",
                'beforeSend': function(jqXHR, settings) {
                    $("#AjaxLoader_" + id).show();
                },
                'success': function(data) {
                    $("#AjaxLoader_" + id).hide();
                    if (data == "success") {
                        $("#get_checked_value_" + id).val('');
                        $("#send_a_msg_box_" + id).hide();
                        $("#send_message_to_users_" + id).hide();
                        $(".view_class_details" + id).show();
                        $(".active_status_class_details" + id).show();
                        $("#send_message_" + id).show();
                        $('#review_cancel_btn_' + id).hide();
                        $("#formResult_" + id).html("Mail Send Successfully .");
                    }
                },
                'cache': false
            });
        }

    }
    function cancelQuery(id) {        
        $("#send_a_msg_box_" + id).hide();
        $("#send_message_" + id).show();
        $('.edit_class_details'+id).show();
        $(".view_class_details" + id).show();
        $(".active_status_class_details" + id).show();
        $("#send_message_to_users_" + id).hide();
        $('#review_cancel_btn_' + id).hide();
    }
    function checkProfile(action) {
        jQuery.ajax({
            'type': 'POST',
            'url': "<?php echo Yii::app()->createAbsoluteUrl("user/profile/checkProfile"); ?>",
            'data': 'action=' + action,
            'beforeSend': function(jqXHR, settings) {
                $("#AjaxLoader").show();
            },
            'success': function(data) {
                $("#AjaxLoader").hide();
                if (data == "false") {
                    $("#formResult").html("Frist complete your profile.");
                    window.setTimeout(function() {
                        $("#AjaxLoader").show();
                        window.location.href = '<?php echo Yii::app()->createAbsoluteUrl("user/profile/updateprofile"); ?>';
                    }, 5000);
                }
                else {
                    window.location.href = data;
                }
            },
            'cache': false
        });
    }
</script>